import { createRouter,createWebHashHistory} from "vue-router";
import store from "@/store"
import { USER_INFO_SESSION_KEY } from "@/store"

import Error from "@/views/404.vue";
import Home from "@/views/Home.vue";

const SHELF_PATH = "/bookshelf";

const routes: Array<RouteRecordRaw> = [
  {
      path: '/',
      redirect: '/home',
      // component: () => import("@v/test.vue")
  },
  {
    path: '/home',
    component: Home,
  },
  {
    path: "/:pathMatch(.*)*",
    name: "*",
    component: Error,
  },
  {
    path: '/category',
    component: () => import("@v/book/Category.vue"),
  },
  {
    path: '/book/:bookId',
    component: () => import("@v/book/BookContent.vue"),
  },
  {
    path: '/book/:bookId/:chapterNum',
    component: () => import("@v/book/ChapterContent.vue")
  },
  {
    path: '/classify',
    component: () => import("@v/classify/Classify.vue")
  },
  {
    path: SHELF_PATH,
    component: () => import("@v/shelf/Bookshelf.vue"),
    // beforeEnter: (to, from, next) => {
    //   // 刷新页面 store 会失去，所以还要判断 sessionStorage
    //   if(store.getters.getUserInfo.username || sessionStorage.getItem(USER_INFO_SESSION_KEY)) {
    //     next()
    //   }
    // }
  },
  {
    path: "/admin",
    component: () => import("@c/admin/Admin.vue"),
  },
  {
    path: "/ar",
    component: () => import("@c/site/sanwenzx/Article.vue"),
  }
];

const router = createRouter({
  history: createWebHashHistory(),
  routes, // `routes: routes` 的缩写
});

export default router;